package com.thkj.modules.home.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.thkj.camera.HikCamerasResoures;
import com.thkj.modules.home.service.HomeService;
import com.thkj.modules.user.entity.LoginRecord;
import com.thkj.modules.user.service.ILoginRecordService;
import com.thkj.modules.user.service.TblConsuUserService;
import com.thkj.modules.user.service.TblIndividualService;
import com.thkj.modules.user.service.TblSecurityAdminService;

import dp.R;
import dp.web.BaseAction;

/**
 *
 */
@RestController
@RequestMapping("/backstage/home")
public class HomeAction extends BaseAction {

	@Autowired
	HomeService homeService;
	@Autowired
	TblConsuUserService tblConsuUserService;

	@Autowired
	TblIndividualService tblIndividualService;

	@Autowired
	TblSecurityAdminService tblSecurityAdminService;

	@Autowired
	ILoginRecordService loginRecordService;

	@RequestMapping("")
	public ModelAndView index() {
		return new ModelAndView("home/index");
	}

	@RequestMapping("/getIndividualTotal")
	public R individualTotal(HttpServletRequest request) {
		// 经营户总数量
		Integer individualTotal = tblIndividualService.count();
		return R.success(individualTotal);
	}

	@RequestMapping("/getLoginRecord")
	public R getLoginRecord() {
		// 查看一周的登录境况
		List<LoginRecord> records = loginRecordService.queryByRecen();
		return R.success(records);
	}

	@RequestMapping("/getSuperviseUserTotal")
	public R superviseUserTotal(HttpServletRequest request) {
		// 监管员总数
		Integer superviseUserTotal = tblSecurityAdminService.queryCountByRoleId("1");
		return R.success(superviseUserTotal);
	}

	@RequestMapping("/getCamersTotal")
	public R camersTotal(HttpServletRequest request) {
		// 摄像头总量
		Integer cameraTotal = HikCamerasResoures.getCount("阳东监管局");
		return R.success(cameraTotal);
	}

	@RequestMapping("/getCustomerTotal")
	public R customerTotal(HttpServletRequest request) {
		// 消费者数量
		Integer customerTotal = tblConsuUserService.queryCount();
		return R.success(customerTotal);
	}

	@RequestMapping("/getAccessTotal")
	public R accessTotal(HttpServletRequest request) {
		// 总访问
		Integer customerTotal = homeService.queryAccessCount();
		return R.success(customerTotal);
	}

}